﻿@model S4Store.Models.AfterSaleReport.AfterSaleDecoratingReportModel
@{
    ViewBag.Title = "CarBrandDecoratingSaleKPI";
    Layout = null;
}

@{
    var config = Model.MonthConfig.FirstOrDefault();
    var daydata = Model.DayData;
    var curday = daydata.Where(o => o.AddTime.Year == DateTime.Now.Year && o.AddTime.Month == DateTime.Now.Month && o.AddTime.Day == DateTime.Now.Day).FirstOrDefault();
    if (curday == null)
    {
        curday = new S4Store.Domain.AfterSaleKpi.AfterSaleCarDecoratingDayInput();
    }
    
    
 }
 @if(config==null || curday==null){
     
     <p>数据未配置（月初或当日）</p>
         
 }else
 {
<div style="height: 100%; overflow: auto">
@Html.Action("ReportBar", "Common", Model.BarModel)
<div class="pagetitle">
    @(config.CarBrand.Name)养护产品销售状况KPI
</div>
<table width="100%" border="0" cellpadding="10" cellspacing="1" class="reporttable">
  <tr>
    <th rowspan="2" align="center"><p>项目数据</p></th>
    <th rowspan="2" align="center" class="tb_header_greenbg"><div><p>养护产品销售率目标</p></div></th>
    <th rowspan="2" align="center"  class="tb_header_greenbg"><div><p>养护产品销售额目标</p></div></th>
    <th rowspan="2" align="center"  class="tb_header_greenbg"><div><p>目标养护产品单车销售额</p></div></th>
    <th colspan="13" align="center"  class="tb_header_greenbg"><p>销售数据
</p></th>
  </tr>
  <tr>
    <th class="tb_header_lightbluebg"><div>已实现养护产品销售台次
</div></th>
    <th class="tb_header_lightbluebg"><div>当日养护产品销售台次
</div></th>

    <th class="tb_header_lightbluebg"><div>累计养护产品销售台次
</div></th>

    <th class="tb_header_lightbluebg"><div>已实现养护产品销售额</div></th>
    <th class="tb_header_lightbluebg"><div>当日养护产品销售总额
</div></th>
    <th class="tb_header_lightbluebg"><div>累计养护产品销售总额
</div></th>


    <th class="tb_header_lightbluebg"><div>养护产品销售进度
</div></th>
    <th class="tb_header_lightbluebg"><div>养护产品销售进度差
</div></th>
    <th class="tb_header_lightbluebg"><div>养护产品销售率
</div></th>
    <th class="tb_header_lightbluebg"><div>养护产品销售率差异
</div></th>
    <th class="tb_header_lightbluebg"><div>平均单车养护产品额
</div></th>
    <th class="tb_header_lightbluebg"><div>单车养护产品额差异
</div></th>
  </tr>
  @{
      var 养护产品销售总台次 = daydata.Sum(o => o.YHCPXSTC_MaintenceSaleNum);
      var 交出总台次 = daydata.Sum(o=>o.JCTC_SaleCarNum);
      var 养护产品销售率 = 交出总台次 == 0 ? 0 : (decimal)养护产品销售总台次 / (decimal)交出总台次;
      
      var 累计养护产品销售总额 = daydata.Sum(o => o.YHCPXSZE_MaintenceSaleTotalVolume);
      var 养护产品销售额目标 = config.YHCPXSEMB_SaleMaintenanceTargetValume;
      var 养护产品销售进度 = 养护产品销售额目标 == 0 ? 0 : 累计养护产品销售总额 / 养护产品销售额目标;
      var 养护产品销售进度差 = 养护产品销售进度 - (decimal)ViewBag.时间进度;

      var 平均单车养护产品销售额 = 养护产品销售总台次 == 0 ? 0 : 累计养护产品销售总额 / (decimal)养护产品销售总台次;
      var 单车用品金额差异 = 平均单车养护产品销售额 - config.YHCPDCXSE_SaleMaintenanceTargetValumeOnUnitCar;
      }
  <tr>
    <td>@config.CarBrand.Name </td>
    <td>@config.YHCPXSLMB_SaleMaintenanceTargetRate %</td>
    <td>@config.YHCPXSEMB_SaleMaintenanceTargetValume</td>
    <td>@config.YHCPDCXSE_SaleMaintenanceTargetValumeOnUnitCar</td>

    <td>@(daydata.Sum(o => o.YHCPXSTC_MaintenceSaleNum) - curday.YHCPXSTC_MaintenceSaleNum)</td>
    <td>@curday.YHCPXSTC_MaintenceSaleNum</td>
    <td>@daydata.Sum(o=>o.YHCPXSTC_MaintenceSaleNum)</td>
    
    <td>@(daydata.Sum(o => o.YHCPXSZE_MaintenceSaleTotalVolume) - curday.YHCPXSZE_MaintenceSaleTotalVolume)</td>
    <td>@curday.YHCPXSZE_MaintenceSaleTotalVolume</td>
    <td>@daydata.Sum(o => o.YHCPXSZE_MaintenceSaleTotalVolume)</td>


    <td>@((养护产品销售进度*100).toInt())%</td>
    <td @if (养护产品销售进度差 < 0)
        {
    <text>style="background:#ff1100"</text>
    }
    
    >@((养护产品销售进度差 * 100).toInt())%</td>


    <td>@((养护产品销售率 * 100).toInt())%</td>
    <td @if ((养护产品销售率 * 100 - config.YHCPXSLMB_SaleMaintenanceTargetRate) < 0)
        {
    <text>style="background:#ff1100"</text>
    }>@((养护产品销售率 * 100 - config.YHCPXSLMB_SaleMaintenanceTargetRate).toInt())%</td>


    

    

    
    <td>@Math.Round(平均单车养护产品销售额, 2, MidpointRounding.AwayFromZero)</td>
    <td@if (单车用品金额差异 < 0)
        {
    <text>style="background:#ff1100"</text>
    }>@Math.Round(单车用品金额差异,2,MidpointRounding.AwayFromZero)</td>



  </tr>
</table>
</div>
}